﻿using System;
using Basmus.ReadWrite;

namespace Basmus.Values.Attributive.ReadWrite
{
    public static class ReflectionHelper
    {
        internal static object GetObjectElementsReaderWriter(Type elementType, object readerWriter)
        {
            var elementsReaderWriter = typeof (ElementsReaderWriter<>)
                .MakeGenericType(elementType)
                .GetConstructor(new[] { typeof(IReaderWriter<>).MakeGenericType(elementType) })
                .Invoke(new[] {readerWriter});
            return typeof (ObjectElementsReaderWriter<>)
                .MakeGenericType(new[] {elementType})
                .GetConstructor(new[] {typeof (IElementsReaderWriter<>).MakeGenericType(elementType)})
                .Invoke(new[] {elementsReaderWriter});
        }
    }
}
